require("../css/login.less");
const axios = require('../utils/axiosUtil.js');

const utils = require('../utils/utils.js');

window.onload = function () {
    let inp = document.querySelector("#inp");
    let inp1 = document.querySelector("#inp1");
    let btn = document.querySelector("button");

    btn.addEventListener("click", function () {
        //非空验证
        if (!(inp.value && inp1.value)) {
            utils.toast(1,"请将数据输入完整");
            return;
        }
        // 正则验证 
        let reg = /^1[3-9][0-9]{9}$/;
        if (!reg.test(inp.value)) {
            utils.toast(1,'请输入正确的手机号');
            return;
        }


        let date = {
            account: inp.value,
            password: inp1.value
        }

        axios.post('/api/user/login', date).then(function (res) {
            if (res.data.errno == 0) {
                utils.toast(0,'登录成功');
                let token = res.data.data.token;
                localStorage.setItem("token",token);
                location.href = './home.html'
            } else {
                utils.toast(1,res.data.message)
            }
        })

    })
    //注册账号
    let item = document.querySelector(".item");
    item.addEventListener("click", function () {
        location.href = "../register.html"
    })




}

